package com.econ.powercloud.ems.controller;

import com.econ.powercloud.common.base.facade.enums.StatusType;
import com.econ.powercloud.common.base.facade.pojo.MsgResult;
import com.econ.powercloud.common.base.facade.pojo.PageResult;
import com.econ.powercloud.ems.aop.UserOperatePower;
import com.econ.powercloud.ems.common.enums.FaultDesc;
import com.econ.powercloud.ems.constant.SysConstant;
import com.econ.powercloud.ems.pojo.EmsAreaVO;
import com.econ.powercloud.ems.pojo.EmsPriceModelDetailVO;
import com.econ.powercloud.ems.pojo.EmsPriceModelVO;
import com.econ.powercloud.ems.pojo.requestVO.EmsPriceModelDetailEditVO;
import com.econ.powercloud.ems.pojo.requestVO.EmsPriceModelDetailRequestVO;
import com.econ.powercloud.ems.service.biz.EPModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Electricity price model - 电价模型
 */
@Api(tags = "电价模型")
@RestController
@RequestMapping(value = "/api/v2/model")
public class EPModelController extends ApiBaseController {

    @Autowired
    private EPModelService epModelService;

    @ApiOperation(value = "查询所有省")
    @GetMapping(value = "getProvinceList")
    public MsgResult<List<EmsAreaVO>> getProvinceList(){
        return successHandler(epModelService.getProvinceList());
    }

    @UserOperatePower
    @ApiOperation(value = "新增电价模型")
    @PostMapping(value = "addModelInfo")
    public MsgResult addModelInfo(@RequestBody @Validated EmsPriceModelVO emsPriceModelVO){
        epModelService.addModelInfo(emsPriceModelVO);
        return MsgResult.builder().status(StatusType.OK.getCode()).statusText(StatusType.OK.getStatusText()).build();
    }

    @ApiOperation(value = "根据省份查询电价模型")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "province",required = false,value = "省", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageNo", value = "页码", defaultValue = "1", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页大小", defaultValue = "20", dataType = "int")
    })
    @GetMapping(value = "selectModelList")
    public MsgResult<PageResult<List<EmsPriceModelVO>>> selectModelInfos(@RequestParam(value = "province", required = false) Integer province,
                                                                         @RequestParam(value = "pageNo", defaultValue = SysConstant.DEFAULT_PAGENO) Integer pageNo,
                                                                         @RequestParam(value = "pageSize", defaultValue = SysConstant.DEFAULT_PAGESIZE) Integer pageSize){
        return successHandler(epModelService.selectModelList(province,pageNo,pageSize));
    }

    @ApiOperation(value = "查询单个电价模型")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "modelId",value = "模块id", dataType = "int"),
    })
    @GetMapping(value = "selectModelById")
    public MsgResult<EmsPriceModelVO> selectModelById(@RequestParam(value = "modelId") Integer modelId){
        return successHandler(epModelService.selectModelById(modelId));
    }

    @ApiOperation(value = "查询电价模型的详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "modelId",value = "模型id", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "applyTime",required = false,value = "适用时间(格式yyyy-MM)", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "priceType",required = false,value = "电价类型", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "voltageLevel",required = false,value = "电压等级", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageNo", value = "页码", defaultValue = "1", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页大小", defaultValue = "20", dataType = "int")
    })
    @GetMapping(value = "selectModelDetailList")
    public MsgResult<PageResult<List<EmsPriceModelDetailVO>>> selectModelDetailList(@RequestParam(value = "modelId")Integer modelId,
                                                                                    @RequestParam(value = "applyTime", required = false) String applyTime,
                                                                                    @RequestParam(value = "priceType", required = false) Integer priceType,
                                                                                    @RequestParam(value = "voltageLevel", required = false) Integer voltageLevel,
                                                                                    @RequestParam(value = "pageNo", defaultValue = SysConstant.DEFAULT_PAGENO) Integer pageNo,
                                                                                    @RequestParam(value = "pageSize", defaultValue = SysConstant.DEFAULT_PAGESIZE) Integer pageSize){
        return successHandler(epModelService.selectModelDetailList(modelId, applyTime, priceType, voltageLevel, pageNo, pageSize));
    }

    @ApiOperation(value = "查询单个电价详情的信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pid",value = "模型详情id", dataType = "int")
    })
    @GetMapping(value = "selectModelDetailInfo")
    public MsgResult<EmsPriceModelDetailVO> selectModelDetailInfo(@RequestParam(value = "pid")Integer pid){
        return successHandler(epModelService.selectModelDetailInfo(pid));
    }

    @UserOperatePower
    @ApiOperation(value = "新增电价")
    @PostMapping(value = "addModelDetail")
    public MsgResult addModelDetail(@RequestBody @Validated EmsPriceModelDetailRequestVO requestVO){
        epModelService.addModelDetail(requestVO);
        return MsgResult.builder().status(StatusType.OK.getCode()).statusText(StatusType.OK.getStatusText()).data(true).build();
    }

    @UserOperatePower
    @ApiOperation(value = "修改电价")
    @PutMapping(value = "modifyModelDetail")
    public MsgResult modifyModelDetail(@RequestBody @Validated EmsPriceModelDetailEditVO requestVO){
        epModelService.modifyModelDetail(requestVO);
        return MsgResult.builder().status(StatusType.OK.getCode()).statusText(StatusType.OK.getStatusText()).data(true).build();
    }

    @UserOperatePower
    @ApiOperation(value = "删除电价")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pid",value = "模型详情id", dataType = "int")
    })
    @DeleteMapping(value = "deleteModelDetail")
    public MsgResult deleteModelDetail(@RequestParam("pid")Integer pid){
        epModelService.deleteModelDetail(pid);
        return MsgResult.builder().status(StatusType.OK.getCode()).statusText(StatusType.OK.getStatusText()).data(true).build();
    }


}
